package com.fire.control.system.config.listener;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.fire.control.system.config.redis.RedisService;
import com.fire.control.system.module.login.service.ILoginService;
import com.fire.control.system.module.system.service.SystemLogService;
import com.fire.control.system.module.user.service.IUserService;


/**
* @ClassName: MyServletContextListener
* @Description: TODO(监听Servlet的创建与销毁)
* @author wanbo
* @date 2017年6月19日 上午10:06:46
*/
@WebListener
public class MyServletContextListener implements ServletContextListener {
	
	private static final Logger logger = LoggerFactory.getLogger(MyHttpSessionListener.class);
	
	public static RedisService redisService;
	public static SystemLogService systemLogService;
	public static ILoginService loginService;
	public static IUserService userService;
	
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        logger.info("--------->ServletContex初始化");
        ServletContext context= sce.getServletContext();
		ApplicationContext ac =  WebApplicationContextUtils.getRequiredWebApplicationContext(context);
		redisService = (RedisService) ac.getBean("redisService");
    	systemLogService = (SystemLogService) ac.getBean("systemLogService");
    	loginService = (ILoginService) ac.getBean("loginService");
    	userService = (IUserService) ac.getBean("userService");
    }
    
    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    	logger.info("--------->ServletContex销毁了");
    }

}